#include"Comm.hpp"
#include"Fifo.hpp"
int main()
{
    key_t key = GetShmKeyOrDir();
    cout<<"key: "<< ToHex(key)<<endl;


    int shmid = GetShm(key,defaultsize);
    std::cout << "shmid: " << shmid << std::endl;

    //客户端和服务端通过同一个shmid拿到同一段共享内存的地址
    char* addr = (char*)ShmAttach(shmid); 
    std::cout << "Attach shm success, addr: " << ToHex((uint64_t)addr) << std::endl;


    memset(addr,0,defaultsize);
    Sync syn;
    syn.OpenWriteDir();
    //可以通信了
    for(char c = 'A'; c <= 'Z'; c++)// pipe, fifo, ->read/write->系统调用， shm -> 没有使用系统调用！！
    {
        addr[c-'A'] = c;
        sleep(1);
        syn.Wakeup();
    }
    ShmDatch(addr);
    std::cout << "Detach shm success, addr: " << ToHex((uint64_t)addr) << std::endl;
    sleep(5);
    return 0;
}